package com.mune.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {
  @Setter
  @Getter
  private List<MemberAddressVo> address; // 收货地址
  @Setter
  @Getter
  private List<OrderItemVo> items; // 订单中的商品信息
  @Setter
  @Getter
  private Integer integration; // 优惠卷（会员积分）
  private BigDecimal payTotal = new BigDecimal("0.00"); // 应付金额
  @Setter
  @Getter
  private Map<Long, Boolean> stocks;
  @Setter
  @Getter
  private String orderToken;

  public BigDecimal getTotal() {
    if (items != null) {
      BigDecimal sum = new BigDecimal("0");
      for (OrderItemVo item : items) {
        sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
      }
      return sum;

    }
    return null;
  }

  public BigDecimal getPayPrice() {
    return getTotal();
  }

  public Integer getCount() {
    Integer i = 0;
    if (items != null) {
      for (OrderItemVo item : items) {
        i += item.getCount();
      }
    }
    return i;
  }
}
